home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15385 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: maui.cc.odu.edu!news
  2. From: "CLEVELAND O. BURNETT" <cob@cs.odu.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Does anyone understand linked lists in C++
  5. Date: Thu, 4 Apr 1996 21:06:11 -0500 (EST)
  6. Organization: Old Dominion University
  7. Message-ID: <Pine.SUN.3.90.960404204802.4582A-100000@daffodil.cs.odu.edu>
  8. NNTP-Posting-Host: daffodil.cs.odu.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  struct students {
  17. char firstname[20];
  18. char middle_initial;
  19. char lastname[20];
  20. char address1[40];
  21. char address2[30];
  22. char phone_number[7];
  23. char email[50];}
  24.  
  25.  
  26. I am trying to do two thing with this structure.  First, I am trying to 
  27. read this struct from a data file that I created and second, I am 
  28. trying to create a linked list of this struct.  The compiler that I am 
  29. using is the g++ compiler.  How would I accomplish this? Please show me 
  30. how can I modify or change my procedures to accomplish my goal?
  31.  
  32. I tried using these procedures that I created and each failed.
  33. The first procedure is for reading the struct and the second is for 
  34. created the linked list
  35.  
  36.  
  37.  
  38. void Read(ifstream &infile, students data)
  39.  
  40. {
  41. infile >> data.firstname[20];
  42.  infile >>data.middle_initial;
  43.  infile >> data.lastname[20];
  44.  infile >> data.address1[40];
  45.  infile >> data.address2[30];
  46.  infile >> data.phone_number[7];
  47.  infile >> data.email[50];
  48.  infile >> data.dept[16];
  49.  infile >> data.edu_level[9];
  50. }
  51.  
  52.  
  53.  
  54.  
  55. void AddLastStudentRec(studentRec &List, students data)
  56. {
  57. Entry newNode = new Node;
  58.  
  59. newNode->data = data;
  60. newNode->next = 0;
  61. if (List.last == NULL)
  62.   {
  63.    List.first = newNode;
  64.    List.last = newNode;
  65.  
  66.  
  67.    else
  68.      {
  69.        List.last->next = newNode;
  70.        List.last = newNode;
  71.        }
  72.        }
  73.  
  74.  
  75.                         thank you,
  76.                 cleveland 
  77.  
  78.  
  79.  
  80.  
  81.